package by.grsu.hdm.devices;

import java.util.ArrayList;
import java.util.List;

import by.grsu.hdm.model.INetworkAvailable;
import by.grsu.hdm.reporting.TrafficReportData;

public class NetworkMonitor {

	private List<INetworkAvailable> devices;

	public NetworkMonitor() {
		this.devices = new ArrayList<INetworkAvailable>();
	}

	public void registerDevice(INetworkAvailable device) {
		this.devices.add(device);
	}

	public TrafficReportData getNetworkStatistics() {
		long inTraffic = 0;
		long outTraffic = 0;

		TrafficReportData reportData = new TrafficReportData();

		for (INetworkAvailable device : this.devices) {
			inTraffic += device.getIncomingTraffic();
			outTraffic += device.getOutgoingTraffic();
		}

		reportData.setOutgoingTraffic(outTraffic);
		reportData.setIncomingTraffic(inTraffic);

		return reportData;
	}
}
